package com.clhbolg.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import com.clhbolg.model.dto.CommentDTO;
import com.clhbolg.model.dto.ReplyDTO;
import com.clhbolg.model.vo.request.CommentVO;
import com.clhbolg.service.ICommentService;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 评论相关接口
 * @Author cailinhu
 * @Description TODO
 * @Date 2023/3/6 15:54
 * @Version 1.0
 */
@RestController
@RequestMapping("/comments")
public class CommentController {

    @Autowired
    ICommentService commentService;
    /**
     * 获取前六个评论
     * @return
     */
    @GetMapping("/topSix")
    public R topSix(){
        List<CommentDTO> commentDTOs= commentService.listTopSixComments();
        return R.ok(commentDTOs);
    }

    /**
     * 获取评论
     * @param commentVO
     * @return
     */
    @GetMapping("/getComments")
    @SaIgnore
    public R getComments(CommentVO commentVO, PageQuery pageQuery) {
        return R.ok(commentService.listComments(commentVO,pageQuery));
    }

    /**
     * 添加评论
     *
     * @param commentVO
     * @return
     */
    @PostMapping("/save")
    public R saveComment(@RequestBody CommentVO commentVO){
        commentService.saveComment(commentVO);
        return R.ok();
    }

    @GetMapping("/{commentId}/replies")
    public R listRepliesByCommentId(@PathVariable("commentId") Long commentId){
        List<ReplyDTO> list= commentService.listRepliesByCommentId(commentId);
        return R.ok(list);
    }



}
